home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / libogg / libvorbis-1.0rc3 / lib / window.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-27  |  1.7 KB  |  63 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
  4.  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
  5.  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6.  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  7.  *                                                                  *
  8.  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
  9.  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  10.  *                                                                  *
  11.  ********************************************************************
  12.  
  13.  function: window functions
  14.  last mod: $Id: window.c,v 1.15 2001/12/20 01:00:30 segher Exp $
  15.  
  16.  ********************************************************************/
  17.  
  18. #include <stdlib.h>
  19. #include <math.h>
  20. #include "os.h"
  21. #include "misc.h"
  22.  
  23. float *_vorbis_window(int type, int window,int left,int right){
  24.   float *ret=_ogg_calloc(window,sizeof(*ret));
  25.  
  26.   switch(type){
  27.   case 0:
  28.     /* The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) */
  29.     {
  30.       int leftbegin=window/4-left/2;
  31.       int rightbegin=window-window/4-right/2;
  32.       int i;
  33.     
  34.       for(i=0;i<left;i++){
  35.     float x=(i+.5f)/left*M_PI/2.;
  36.     x=sin(x);
  37.     x*=x;
  38.     x*=M_PI/2.f;
  39.     x=sin(x);
  40.     ret[i+leftbegin]=x;
  41.       }
  42.       
  43.       for(i=leftbegin+left;i<rightbegin;i++)
  44.     ret[i]=1.f;
  45.       
  46.       for(i=0;i<right;i++){
  47.     float x=(right-i-.5f)/right*M_PI/2.;
  48.     x=sin(x);
  49.     x*=x;
  50.     x*=M_PI/2.f;
  51.     x=sin(x);
  52.     ret[i+rightbegin]=x;
  53.       }
  54.     }
  55.     break;
  56.   default:
  57.     _ogg_free(ret);
  58.     return(NULL);
  59.   }
  60.   return(ret);
  61. }
  62.  
  63.